\documentclass{article}

\usepackage{geometry} % 文档四周边界
\geometry{a4paper, left=2.5cm, right=2.5cm, top=1.5cm, bottom=1.5cm}

\usepackage{ctex}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}

\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=orange!30]
\tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]

\begin{document}
\title{程序流程图示例}
\author{作者名}
\date{\today}
\maketitle

\section{流程图示例}

下面是一个使用TikZ宏包绘制的程序流程图示例：

\begin{figure}[h]
\centering

\begin{tikzpicture}[node distance=2cm]

\node (start) [startstop] {开始};
\node (input) [process, below of=start] {输入数字 n};
\node (decision) [decision, below of=input, yshift=-0.5cm] {n 是偶数吗？};
\node (output1) [process, below of=decision, yshift=-0.5cm] {输出 "偶数"};
\node (output2) [process, right of=decision, xshift=2.5cm] {输出 "奇数"};
\node (end) [startstop, below of=output1] {结束};

\draw [arrow] (start) -- (input);
\draw [arrow] (input) -- (decision);
\draw [arrow] (decision) -- node[anchor=east] {是} (output1);
\draw [arrow] (decision) -- node[anchor=south] {否} (output2);
\draw [arrow] (output2) |- (end); % 从右下角连接到结束节点
\draw [arrow] (output1) -- (end);

\end{tikzpicture}
\caption{一个程序流程图}
\label{fig-1}
\end{figure}

\end{document}
